/*
 * srv.cpp
 *
 *  Created on: Jun 14, 2021
 *      Author: tau
 */

#include "srv.h"
#include <board.h>
#include "Fram.h"
#include <unistd.h>
#include <fcntl.h>
#include "cjson/cJSON.h"
#include "stdio.h"
#include "string.h"

static sysBase_t __sysVar;
static sysConst_u __sysConst;
Fram* Fram0;

static void sysConstDataRecover(void){
	__sysConst.sysConst.currentLanguage = 0;
	__sysConst.sysConst.chipCheck = CHIPCHECK;
	__sysConst.sysConst.savedProgrameIndex= 0;
	__sysConst.sysConst.savedTotalCounter= 0;
	__sysConst.sysConst.savedFinishedCounter= 0;

	saveSysConst();
}

void saveSysConst(void){
	Fram0->writeMem(0, sizeof(sysConst_u), __sysConst.data);
}

static void sysDBInit(void){
	Fram0 = new Fram(0xcb,0xcc);
	Fram0->readMem(0, sizeof(sysConst_u), __sysConst.data);
	if(__sysConst.sysConst.chipCheck != CHIPCHECK){
		sysConstDataRecover();
	}
}
sysBase_t* getSystemVar(void){
	return &__sysVar;
}

sysConst_u* getSystemConst(void){
	return &(__sysConst);
}


